import { provide, ref } from "vue";
import api from "@/utils";
import { AxiosResponse } from "axios";
import { Annex } from "@/models/Annex";

export default function AnnexDialogEvent() {
  const annexDialogVisible = ref(false);
  provide("annexDialogVisible", annexDialogVisible);

  const changeAnnexDialogVisible = () => {
    annexDialogVisible.value = !annexDialogVisible.value;
  };
  provide("changeAnnexDialogVisible", changeAnnexDialogVisible);

  const annexList = ref([] as Annex[]);

  const getAnnexList = (tableName: string, rowId: number) => {
    api.http
      .get("/annex/" + tableName + "/" + rowId)
      .then((res: AxiosResponse) => {
        annexList.value = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
  };
  provide("getAnnexList", getAnnexList);

  return {
    annexList,
    annexDialogVisible,
    changeAnnexDialogVisible,
    getAnnexList,
  };
}
